import Router from '@koa/router';
import { validateDto } from '../../../middleware/validation';
import { AuthMiddleware } from '../../../middleware/authMiddleware';
import { TenantController } from '../../../controllers/system/tenantController';
import { CreateTenantDto, UpdateTenantDto } from '../../../dtos/system/TenantDto';
const router = new Router();
const tenantController = new TenantController();
const authMiddleware = new AuthMiddleware();

// 获取所有租户（需要认证）
router.get('/', authMiddleware.authenticate, tenantController.getTenants);

// 根据ID获取租户（需要认证）
router.get('/:id', authMiddleware.authenticate, tenantController.getTenantById);

// 创建租户（需要认证，仅管理员）
router.post('/', authMiddleware.authenticate, authMiddleware.requireRole('admin'), validateDto(CreateTenantDto), tenantController.createTenant);

// 更新租户（需要认证，仅管理员）
router.put('/:id', authMiddleware.authenticate, validateDto(UpdateTenantDto, { skipMissingProperties: true }), tenantController.updateTenant);

// 删除租户（需要认证，仅管理员）
router.delete('/:id', authMiddleware.authenticate, authMiddleware.requireRole('admin'), tenantController.deleteTenant);

export default router;